#封装app变量
from flask import Flask
from flask_script import Manager
#封装db变量
from flask_sqlalchemy import SQLAlchemy
import os

#实现类继承Flask类
class Application(Flask):
    #实现初始化方法
    def __init__(self,import_name,template_folder = None,root_path = None):
        super(Application,self).__init__(import_name,template_folder=template_folder,root_path=root_path,static_folder=None)
        #加载配置文件    self.config.from_pyfile  加载配置信息
        self.config.from_pyfile('config/base_setting.py')
        #加载不同环境下的配置文件
        if "ops_config" in os.environ:
            self.config.from_pyfile('config/%s_setting.py'%os.environ['ops_config'])
        #重新初始化变量
        db.init_app(self)
#        app.config['SQLALCHEMY_DATABASE_URL] = 'mysql：//root：123456@127.0.0.1'
db = SQLAlchemy()
app = Application(__name__,template_folder=os.getcwd() + "/web/templates/",root_path=os.getcwd())
manager =   Manager(app)

#函数模板
from common.libs.UrlManager import UrlManager
app.add_template_global(UrlManager.buildStaticUrl,'buildStaticUrl')
app.add_template_global(UrlManager.buildUrl,'buildUrl')
app.add_template_global(UrlManager.buildImageUrl,'buildImageUrl')